<template>
  <div class="table-page-search-wrapper">
    <el-form :model="searchForm" ref="searchForm" label-width="100px" class="demo-ruleForm">
      <el-row :gutter="10">
        <el-col :md="8" :sm="12" :xs="24" style="padding:0 8px;">
          <el-form-item label="商品名称:">
            <el-input v-model="searchForm.goodsName" placeholder="请输入商品名称" />
          </el-form-item>
        </el-col>
        <el-col :md="8" :sm="12" :xs="24" style="padding:0 8px;">
          <el-form-item label="条形码:">
            <el-input v-model="searchForm.barCode" @keyup.enter.native="searchAction()" placeholder="请输入条形码" />
          </el-form-item>
        </el-col>
        <el-col :md="6" :sm="12" :xs="24">
          <el-form-item label="商品类目:">
            <el-cascader
              :options="categoryIdList"
              v-model="pid"
              @change="categoryIdChange"
              placeholder="请选择商品类目"
              style="width:100%"
            ></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :md="8" :sm="12" :xs="24" style="padding:0 8px;">
          <el-form-item label="商品状态:">
            <el-select v-model="searchForm.goodsStatus" placeholder="请选择商品状态" style="width:100%">
              <el-option
                v-for="item in zhuangtaiList"
                :key="item.value"
                :value="item.value"
                :label="item.label"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :md="8" :sm="12" :xs="24" style="padding:0 8px;">
          <el-form-item label="供应商:">
            <!-- <el-select
              v-model="searchForm.platformMerchantId"
              placeholder="请选择供应商"
              style="width:100%"
              filterable
            >
              <el-option
                v-for="item in supplierMerchantIdList"
                :key="item.value"
                :value="item.value"
                :label="item.label"
              ></el-option>
            </el-select>-->
            <el-input v-model="searchForm.supplierMerchantName" placeholder="请输入供应商名称" />
          </el-form-item>
        </el-col>
        <el-col :md="8" :sm="12" :xs="24" style="padding:0 8px;">
          <div style="margin-left:30px">
            <el-button type="primary" icon="el-icon-search" @click="searchAction()">查询</el-button>
            <el-button icon="el-icon-refresh" @click="resetSearch()" style="margin-left: 8px;">重置</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import {
  merchantinfofetchList,
  platformgoodscategorytree,
} from "@/api/shop/goods/list.js";
export default {
  name: "search",
  props: ["keyName", "businessType"],
  data() {
    return {
      leimuList: [], //商品类目
      zhuangtaiList: [
        {
          label: "全部",
          value: "",
        },
        {
          label: "停售",
          value: "00",
        },
        {
          label: "在售",
          value: "01",
        },
      ],
      //商品状态
      searchForm: {},
      supplierMerchantIdList: [], //供应商
      pid: [],
      categoryIdList: [],
    };
  },
  // mounted() {
  //   this.getList();
  // },
  methods: {
    searchAction() {
      //执行搜索
      this.$emit("search");
    },
    resetSearch() {
      this.searchForm = {};
      this.pid = [];
      this.$emit("resetSearch");
    },
    getSearchForm() {
      //获取高级搜索条件
      return {
        ...this.searchForm,
      };
    },
    getList(businessType) {
      this.categoryIdList = [];
      platformgoodscategorytree({ businessType: businessType }).then((val) => {
        //类目
        //商品类目
        let data = val.data.data;
        console.log(data);
        this.categoryIdList = data.map((item) => {
          return {
            value: item.categoryId,
            label: item.categoryName,
            children: item.children.map((items) => {
              return {
                value: items.categoryId,
                label: items.categoryName,
              };
            }),
          };
        });
      });
      merchantinfofetchList().then((val) => {
        //供应商
        console.log(val);
        let data = val.data.data;
        this.supplierMerchantIdList = data.map((item) => {
          return {
            value: item.merchantId,
            label: item.companyName,
          };
        });
      });
    },
    categoryIdChange(e) {
      if (e.length > 1) {
        this.searchForm.categoryId = e[1];
      } else {
        this.searchForm.categoryId = e[0];
      }
    },
  },
};
</script>


<style lang="less">
</style>>
